<template>
  <div :class="prefixCls" class="relative w-full h-full px-4">
    <AppLocalePicker class="absolute text-white top-4 right-4 enter-x xl:text-gray-600" :showText="false" v-if="!sessionTimeout && showLocale" />
    <AppDarkModeToggle class="absolute top-3 right-7 enter-x" v-if="!sessionTimeout" v-show="false"/>
    <span class="-enter-x xxl:hidden">
      <!--AppLogo :alwaysShowTitle="true" /-->
    </span>
    <div class="loginTitle">
      <div class="mt-10 font-medium -enter-x"></div>
    </div>
    <div class="loginbox">
      <div class="top -xl:hidden">
        <div class="header">
          <a href="/">
            <!--img :alt="title" src="../../../assets/svg/login-box-bg.svg" class="logo" alt="logo"-->
            <span class="title"></span><br>
            <span class="title"></span>
          </a>
        </div>
        <div class="desc"></div>
      </div>
      <div class="flex w-full h-full py-5 xl:h-auto xl:py-0 xl:my-0 xl:w-6/12" >
        <div
          :class="`${prefixCls}-form`"
          class="relative w-full px-5 py-8 mx-auto my-auto rounded-md shadow-md xl:ml-8 xl:bg-transparent sm:px-8 xl:p-4 xl:shadow-none sm:w-3/4 lg:w-2/4 xl:w-11/12 enter-x"
        >
          <LoginForm />
          <RegisterForm />
          <MobileForm />
          <QrCodeForm />
        </div>
      </div>
    </div>
    <div class="footer">
      <div class="copyright">正直诚信 追求卓越 积极创新 智慧旅游 分享共赢 快乐生活</div> <!-- 勇于挑战 -->
      <div class="links">
        <span><a href="http://beian.miit.gov.cn/"><h5 class="white" id="id-company-text">{{companyText}}</h5></a></span>
      </div>
    </div>
  </div>
</template>
<script lang="ts" setup>
  import { computed, ref } from 'vue';
  import { AppLogo } from '/@/components/Application';
  import { AppLocalePicker } from '/@/components/Application';
  import { AppDarkModeToggle } from '/@/components/Application';
  import LoginForm from './LoginForm.vue';
  import ForgetPasswordForm from './ForgetPasswordForm.vue';
  import RegisterForm from './RegisterForm.vue';
  import MobileForm from './MobileForm.vue';
  import QrCodeForm from './QrCodeForm.vue';
  import { useGlobSetting } from '/@/hooks/setting';
  import { useI18n } from '/@/hooks/web/useI18n';
  import { useDesign } from '/@/hooks/web/useDesign';
  import { useLocaleStore } from '/@/store/modules/locale';
  import { useLoginState, LoginStateEnum } from './useLogin';
  defineProps({
    sessionTimeout: {
      type: Boolean,
    },
  });

  const globSetting = useGlobSetting();
  const { prefixCls } = useDesign('login');
  const { t } = useI18n();
  const localeStore = useLocaleStore();
  const showLocale = localeStore.getShowPicker;
  const title = computed(() => globSetting?.title ?? '');

  const companyText = computed(() => {
    let url = window.location.href;
    let res = "备案号 桂ICP备14002690号";
    if (url.indexOf("nnxyy.cc") > -1) {
      res = res + "-2";
    } else if (url.indexOf("yygj.vip") > -1) {
      res = res + "";
    } else if (url.indexOf("yygj.top") > -1) {
      res = res + "-7";  
    } else if (url.indexOf("nnxyy.vip") > -1) {
      res = res + "-4";
    } else if (url.indexOf("gxzm.vip") > -1) {
      res = res + "-5";
    } else if (url.indexOf("gxyyhy.vip") > -1) {
      res =  "备案号 桂ICP备2022007387号-1";
    } else if (url.indexOf("localhost") > -1 || url.indexOf("127.0.0.1") > -1) {
      res = res
    } else {
      res =  "";
    }
    console.info("res@", url, url.indexOf("localhost"), res)
    return res;
  });

  const { handleBackLogin } = useLoginState();
  handleBackLogin();

</script>
<style lang="less" scoped>
  @prefix-cls: ~'@{namespace}-login';
  @logo-prefix-cls: ~'@{namespace}-app-logo';
  @countdown-prefix-cls: ~'@{namespace}-countdown-input';
  @dark-bg: #293146;

  html[data-theme='dark'] {
    .@{prefix-cls} {
      background-color: @dark-bg;

      &::before {
        background-image: url(/@/assets/svg/login-bg-dark.svg);
      }

      .ant-input,
      .ant-input-password {
        background-color: #232a3b;
      }

      .ant-btn:not(.ant-btn-link):not(.ant-btn-primary) {
        border: 1px solid #4a5569;
      }

      &-form {
        background: transparent !important;
      }

      .app-iconify {
        color: #fff;
      }
    }

    input.fix-auto-fill,
    .fix-auto-fill input {
      -webkit-text-fill-color: #c9d1d9 !important;
      box-shadow: inherit !important;
    }
  }

  .@{prefix-cls} {
    min-height: 100%;
    overflow: hidden;
    vertical-align: middle;
    display: flex;
    @media (max-width: @screen-xl) {
      background-color: #293146;

      .@{prefix-cls}-form {
        background-color: #fff;
      }
    }

    &::before {
      position: absolute;
      top: 0;
      left: 0;
      width: 100%;
      height: 100%;
      //margin-left: -48%;
      background-image: url(/@/assets/svg/login-bg.svg);
      background-position: 100%;
      background-repeat: no-repeat;
      background-size: auto 100%;
      content: '';
      @media (max-width: @screen-xl) {
        display: none;
      }
    }

    .@{logo-prefix-cls} {
      position: absolute;
      top: 50px;
      left: 500px;
      height: 30px;

      &__title {
        font-size: 16px;
        //color: #fff;
      }

      img {
        width: 32px;
      }
    }

    .container {
      .@{logo-prefix-cls} {
        display: flex;
        width: 60%;
        height: 80px;

        &__title {
          font-size: 24px;
          color: #fff;
        }

        img {
          width: 48px;
        }
      }
    }

    &-sign-in-way {
      .anticon {
        font-size: 22px;
        color: #888;
        cursor: pointer;

        &:hover {
          color: @primary-color;
        }
      }
    }

    .ant-input-password {
      .ant-input {
        width: calc(100% - 25px);
      }
    }

    input:not([type='checkbox']) {
      min-width: 200px;

      @media (max-width: @screen-xl) {
        min-width: 320px;
      }

      @media (max-width: @screen-lg) {
        min-width: 260px;
      }

      @media (max-width: @screen-md) {
        min-width: 240px;
      }

      @media (max-width: @screen-sm) {
        min-width: 160px;
      }
    }

    .@{countdown-prefix-cls} input {
      min-width: unset;
    }

    .ant-divider-inner-text {
      font-size: 12px;
      color: @text-color-secondary;
    }

    //-------------------------------------------------------------------------
    .loginbox {
      width: 800px;
      height: 500px;
      margin: auto;
      background: #ffffff;
      box-shadow: 0 5px 15px rgba(0, 0, 0, 0.15);
      border-radius: 8px;
    }
    .top {
      text-align: center;
      width: 355px;
      height: 500px;
      background: url(/@/assets/login-bg.png) no-repeat center top;
      float:left;
      .header {
        height: 44px;
        line-height: 44px;
        .badge {
          position: absolute;
          display: inline-block;
          line-height: 1;
          vertical-align: middle;
          margin-left: -12px;
          margin-top: -10px;
          opacity: 0.8;
        }

        .logo {
          height: 60px;
          width: 100%;
          vertical-align: top;
          margin-top: 110px;
          margin-bottom: 10px;
          border-style: none;
        }

        .title {
          font-size: 24px;
          color: #ffffff;
          font-family: Avenir, 'Helvetica Neue', Arial, Helvetica, sans-serif;
          font-weight: 600;
          position: relative;
          top: 2px;
        }
      }
      .desc {
        font-size: 14px;
        color: rgba(0, 0, 0, 0.45);
        margin-top: 12px;
        margin-bottom: 40px;
      }
    }

    .main {
      width: 445px;
      height:500px;
      margin: 0 auto;
      float:left;
      display: block;
      padding: 0 30px;
      position: relative;
    }

    .footer {
      position: absolute;
      width: 100%;
      bottom: 0;
      padding: 0 16px;
      margin: 48px 0 5px;
      text-align: center;
      .links {
        margin-top: 5px;
        margin-bottom: 8px;
        font-size: 14px;
        a {
          color: rgba(0, 0, 0, 0.45);
          transition: all 0.3s;
          &:not(:last-child) {
            margin-right: 40px;
          }
        }
      }
      .copyright {
        color: rgba(0, 0, 0, 0.45);
        font-size: 14px;
      }
    }
  }
</style>
